function doComplete(e,r,s)
{
    var error='';
    if(e.responseXML)
        if(e.responseXML.documentElement.firstChild.firstChild.tagName=='error-name'){
            var error=e.responseXML.documentElement.firstChild.firstChild.textContent;
            document.getElementById('errorpage:error').value=error;
            document.forms['errorpage'].submit()
        }
}
var initArray=[];
var disposeArray=[];

function dispose(){
    for(var i=0;i<disposeArray.length;i++)    
    {
        disposeArray[i]();
    }
}

function init(){
    $("a[href='"+curr_menuitem+"']").toggleClass('ui-state-hover')
    for(var i=0;i<initArray.length;i++)    
    {
        initArray[i]();
    }
    if(typeof(jsf)!="undefined") jsf.ajax.addOnError(doComplete);
    if(typeof($)!="undefined"){

        $('#errorpage').ajaxComplete(function(event,request, settings){
            //$(this).append('<li>Request Complete.</li>');
            doComplete(request,event,settings);
        });
        $('#errorpage').ajaxError(function(event,request, settings){
            //$(this).append('<li>Request Complete.</li>');
            doComplete(request,event,settings);
        });
    }
    initfg();
}

function getInternetExplorerVersion()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat( RegExp.$1 );
    }
    return rv;
}
function initfg()
{
    $(function(){
        //all hover and click logic for buttons
        $(".fg-button:not(.ui-state-disabled)")
        .hover(
            function(){ 
                $(this).addClass("ui-state-hover"); 
            },
            function(){ 
                $(this).removeClass("ui-state-hover"); 
            }
            )
        .mousedown(function(){
            $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
            if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){
                $(this).removeClass("ui-state-active");
            }
            else {
                $(this).addClass("ui-state-active");
            }	
        })
        .mouseup(function(){
            if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
                $(this).removeClass("ui-state-active");
            }
        });
    });
}